package info.rongtong.service.impl;

import info.rongtong.domain.Article;
import info.rongtong.service.basic.BasicServiceImpl;
import info.rongtong.service.inter.ArticleServiceInter;

import java.util.List;

public class ArticleServiceImpl extends BasicServiceImpl implements
		ArticleServiceInter {

	public List getArticleOrderBy(Integer pageNow,Integer pageSize) {
		String hql="from Article a inner join a.category order by a.atop desc,a.atime desc,a.apeak desc ";
		List list = null;
		try {
			list =this.executeQuery(Article.class, hql, null, pageNow, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	public List getArticleOrderBy(Integer pageNow,Integer pageSize,Integer cid) {
		String hql="from Article a inner join a.category where a.category.cid= ? order by  a.atop desc,a.atime desc,a.apeak desc ";
		Object[] obj = {cid};
		return this.executeQuery(Article.class, hql, obj, pageNow, pageSize);
	}

	public Integer getPageCount(Integer pageSize) {
		String hql="select count(*) from Article";
		Integer pageCount =Integer.parseInt(this.uniqueResult(hql, null).toString());
		return ((pageCount-1)/pageSize+1);
	}
	public Integer getPageCountByCategory(Integer pageSize, Integer cid) {
		String hql="select count(*) from Article a inner join a.category where a.category.cid= ?";
		Object[] obj ={cid};
		Integer pageCount =Integer.parseInt(this.uniqueResult(hql, obj).toString());
		return ((pageCount-1)/pageSize+1);
	}
	public Object getArticleById(Integer aid) {
		String hql="from Article a inner join a.category c where a.category.cid=c.cid and a.aid=?";
		Object[] obj={aid};
		return this.uniqueResult(hql, obj);
	}
	
}
